package de.szut.traineeslife.adapter;

import java.util.ArrayList;

import com.google.api.services.drive.model.File;

import de.szut.traineeslife.R;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class FilesFromDriveAdapter extends ArrayAdapter<File> {
	private Context mContext;
	private ArrayList<File> mFileList;
	private TextView fileName;
	private TextView fileCreated;

	/**Is the adapter to display the Files that was uploaded to Drive
	 * @param context
	 * @param textViewResourceId
	 * @param fileList
	 */
	public FilesFromDriveAdapter(Context context, int textViewResourceId,ArrayList<File> fileList) {
		super(context, textViewResourceId,fileList);
		this.mContext = context;
		this.mFileList = fileList;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		File file;
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = inflater.inflate(R.layout.drive_list_item, parent, false);
			fileName = (TextView) v.findViewById(R.id.item_name);
			fileCreated = (TextView) v.findViewById(R.id.item_path);
		} else {
			file = mFileList.get(position);
			v.setTag(file.getTitle());
		}
		file = mFileList.get(position);
		if (file != null) {
			Log.d("DRIVEADAPTER",file.getTitle());
			fileName.setText(file.getTitle());
			fileCreated.setText(file.getCreatedDate().toStringRfc3339());
		}
		return v;
	}
}
